package com.example.gamestore.control;

import com.example.gamestore.Bean.Content;
import com.example.gamestore.mapper.ContentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class AdminContentControl {
    @Autowired
    private ContentMapper contentMapper;
    @GetMapping("/admin/content")
    public String getcontent(@RequestParam(name = "pn",defaultValue = "1")Integer pn, Model model){
        PageHelper.startPage(pn,5);
        List<Content> contents = contentMapper.selectList(null);
        PageInfo<Content> info=new PageInfo<>(contents,5);
        model.addAttribute("pages",info);
        return "Admin/content";
    }
    @PostMapping("/admin/deletecontent")
    @ResponseBody
    public String deleteContent(Integer id){
        contentMapper.deleteById(id);
        return "删除成功";
    }
}
